--- title: "L2-023 图着色问题" created: 2025-11-28 tags: - 算法 --- # L2-023 图着色问题 ## 题目 [L2-023 图着色问题](https://pintia.cn/problem-sets/994805046380707840/exam/problems/type/7?problemSetProblemId=994805057298481152&page=1) ![[image-28c64c36.png]] ## 思路分析 无向图 用邻接矩阵存 要求判断联通的两个点颜色不同 ## 代码实现 ```typescript #include using namespace std; #define int long long #define endl '\n' using ll = long long; using ull = unsigned long long; using PII = pair; using Pll = pair; int dx[4]= {-1,0,1,0},dy[4]= {0,1,0,-1}; const int inf = 0x3f3f3f3f; priority_queue pq; multiset s; vector> g; bool check(int a,int b) { cout<<"check: "<>v>>e>>k;//v个点 e条边 k种颜色 g.resize(v+1,vector(v+1,0)); while(e--) { int a,b; cin>>a>>b; g[a][b] = g[b][a] = 1; } // for(int i=1; i<=v; i++) { // for(int j=1; j<=v; j++) { // cout<>n; while(n--) { vector colors(v+1); unordered_set colorSet; for(int i=1; i<=v; i++) { cin>>colors[i]; colorSet.insert(colors[i]); } if(colorSet.size()!=k) { cout<<"No"<